// 里面引入request,然后请求一级分类列表
import request from "@/utils/request";
import { type } from "os";

//把这些数据暴露再去，还要给他们限制类型
export interface reqCategoryItemType {
    id:number;
    name:string;
    category1Id?:number;
    category2Id?:number;
}

//让它的类型组成一个数组
export type reqCategoryType = reqCategoryItemType[];

//1.请求一级分类列表
export const requestCategory1 = () =>{
    return request.get<any,reqCategoryType>(
    `/admin/product/getCategory1`)
};

//2.请求二级分类列表
// 这个要接收它的一个参数，然后还要给它的这个参数限制类型
export const requestCategory2 = (category1Id:number) =>{
    return request.get<any,reqCategoryType>(
    `/admin/product/getCategory2/${category1Id}`)
};

//3.请求三级分类列表
export const requestCategory3 = (category2Id:number) =>{
    return request.get<any,reqCategoryType>(
    `/admin/product/getCategory3/${category2Id}`)
};

/* 以下是Attr的内容 */

//某个属性内属性值列表的类型
export interface attrValueListType {
    id?: number;
    valueName: string;
    attrId: number | undefined;
    isEdit?: boolean;
  }
  
//某个属性的类型
export interface attrListItemType {
    id?:number;
    attrName:string;
    categoryId:number;
    categoryLevel:number;
    attrValueList: attrValueListType[];
    attrIdValueId?: string;
}

//属性列表的类型
export type attrListType = attrListItemType [];

// 4.获取列表的类型
export const requestAttrList = (
    category1Id: number,
    category2Id: number,
    category3Id: number,
) =>{
    return request.get <any,attrListType>(
        `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
    );
};

//5删除某个属性
export const requestDeleteAttr = (attrId: number) => {
    return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`);
  };
  
  //6.新增或修改属性
  export const requestUpdateOrAddAttr = (newAttr: attrListItemType) => {
    return request.post<any, null>(`/admin/product/saveAttrInfo`, newAttr);
  };
  